home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- * *
- * MacPaintImport.c *
- * *
- * Translator for reading a MacPaint file with XTND 1.3. *
- * *
- * Copyright © 1988 Claris Corporation *
- * All Rights Reserved *
- * *
- * Author: Michael Hilton *
- * Date: 15 July, 1988 *
- * *
- ************************************************************************/
-
- #include <QuickDraw.h>
- #include <StandardFile.h>
- #include <Memory.h>
- #include <Errors.h>
- #include <ToolUtils.h>
-
- #include ":::XTND Headers:XTNDCIncludes:XTNDPictTranslator.h"
-
- /*------------------------- Useful Constants ---------------------------*/
-
- #define PNTGHEADERSIZE 512
- #define UNCOMPRESSEDDATASIZE 51840
-
-
- /*-------------------------Function prototypes--------------------------*/
-
- void main(PictImportParmBlkPtr);
- static void ImportPaint(PictImportParmBlkPtr);
-
-
- /*----------------------------------------------------------------------*/
- /* main This is the main routine and the only entry point for the */
- /* the translator. */
- /*----------------------------------------------------------------------*/
- void main(ourPtr)
- PictImportParmBlkPtr ourPtr;
- {
- ImportPaint(ourPtr); /* Keep things simple at the highest level */
- }
-
-
- /*----------------------------------------------------------------------*/
- /* ImportPict This routine actually performs all of the work of the */
- /* translator. It reads and uncompresses the MacPaint file */
- /* and creates a PICT which is returned to the application. */
- /*----------------------------------------------------------------------*/
- static void ImportPaint(ourPtr)
- register PictImportParmBlkPtr ourPtr;
- {
- register short i;
- register Ptr saveSource,saveDest;
- register long saveDataSize;
-
- Ptr source, dest;
- long dataSize;
- GrafPtr savePort,tempPort;
- BitMap theBits, saveBits;
- PicHandle thePicture;
-
- ourPtr->result = noErr;
-
- if (ourPtr->directive != importGetPict) /* Check for a valid directive */
- return;
-
- /* Determine the size of the compressed data (= size of the file - 512) */
- GetEOF(ourPtr->dataRefNum, &dataSize); /* Get the size of the file */
- dataSize -= PNTGHEADERSIZE; /* Subtract the size of the header */
- saveDataSize = dataSize; /* Save it for later */
-
- saveSource = source = NewPtr(dataSize); /* Create the source ptr */
- if (ourPtr->result = MemError())
- return;
-
- /* skip over the header information */
- if (ourPtr->result = SetFPos(ourPtr->dataRefNum, fsFromStart, PNTGHEADERSIZE)) {
- DisposPtr(source);
- return;
- }
-
- /* Read in the compressed data */
- if (ourPtr->result = FSRead(ourPtr->dataRefNum, &dataSize, source)) {
- DisposPtr(source);
- return;
- }
-
- if (saveDataSize != dataSize) { /* If we failed to read in the compressed data */
- DisposPtr(source);
- ourPtr->result = ioErr;
- return;
- }
-
- /* We have successfully read in the compressed data */
- saveDest = dest = NewPtr(UNCOMPRESSEDDATASIZE); /* Create the dest ptr */
- if (ourPtr->result = MemError()) {
- DisposPtr(source);
- return;
- }
-
- for (i = 0; i < 720; i++)
- UnpackBits(&source, &dest, 72); /* Unpack the compressed data. */
-
- DisposPtr(saveSource); /* Get rid of the source ptr */
- GetPort(&savePort); /* save the current port */
-
- /* open a new port (the current port may be a color port) */
- tempPort = (GrafPtr)NewPtr(sizeof(GrafPort));
- if (ourPtr->result = MemError()) {
- DisposPtr(saveDest);
- return;
- }
- OpenPort(tempPort);
- SetPort(tempPort);
-
- /* Set clipping so drawing will work */
- SetRect(&(*tempPort->clipRgn)->rgnBBox, -8000, -8000, 8000, 8000);
- saveBits = tempPort->portBits;
-
- theBits.baseAddr = saveDest; /* Set up new BitMap */
- theBits.rowBytes = 72; /* width of image */
- SetRect(&theBits.bounds, 0, 0, 576, 720);
- SetPortBits(&theBits); /* set new port to use the new BitMap */
-
- thePicture = OpenPicture(&theBits.bounds); /* Open the Picture */
-
- /* Now do a CopyBits to record the bits into the new Picture */
- CopyBits(&theBits, &theBits, &theBits.bounds, &theBits.bounds, srcCopy, 0);
- ClosePicture(); /* Finished creating picture */
-
- SetPortBits(&saveBits);
- DisposPtr(saveDest); /* Get rid of the dest ptr */
- SetPort(savePort); /* set port back to the original port */
-
- ClosePort(tempPort); /* get rid of our temporary port */
- DisposPtr((Ptr) tempPort);
-
- /* We're done!! Return the picture. */
- ourPtr->thePicture = thePicture;
- }
-
-